In [1]:
import pandas as pd
import numpy as np
import datetime as dt
import yfinance as yf
#from pandas_datareader import data as pdr
import datetime
from datetime import date
today = datetime.datetime.now()

n_of_stocks=108
         
class Stocks:
    def __init__(self,stock_id,stock_index):
        self.id=stock_id
        self.data=yf.download(stock_index, start="2019-08-02", end=today)
        self.stock_hist=np.array(self.data['Close'])
        self.rolling_mean=self.data.Close.rolling(window=20).mean()
        self.rolling_mean2=self.data.Close.rolling(window=50).mean()
        self.exp=self.data.Close.ewm(span=20, adjust=False).mean()
        self.exp2=self.data.Close.ewm(span=50, adjust=False).mean()      
       
            
            
        
indeces= ["AFYON.IS","AKBNK.IS","AKSA.IS","AKSEN.IS","ALGYO.IS","ALARK.IS","ALBRK.IS","ANACM.IS",
        "AEFES.IS","ANELE.IS","ARCLK.IS","ASELS.IS","BERA.IS",
         "BJKAS.IS","BIMAS.IS","CLEBI.IS","CEMAS.IS","CEMTS.IS",
        "CCOLA.IS","DEVA.IS","DOHOL.IS","ECILC.IS","ECZYT.IS",
         "EGEEN.IS","EKGYO.IS","ENJSA.IS","ENKAI.IS","EREGL.IS",
         "FENER.IS","FLAP.IS","FROTO.IS","GARAN.IS",
         "GENTS.IS","GEREL.IS","GLYHO.IS","GOLTS.IS","GOODY.IS",
         "GOZDE.IS","GSRAY.IS","GSDHO.IS","GUBRF.IS","SAHOL.IS",
         "HEKTS.IS","HURGZ.IS","ICBCT.IS","IHLGM.IS",
         "IHLAS.IS","INDES.IS","IPEKE.IS","ISGYO.IS","ISDMR.IS",
         "ITTFH.IS","KRDMD.IS","KARSN.IS","KARTN.IS","DGKLB.IS",
         "KERVT.IS","KCHOL.IS","KORDS.IS","KOZAL.IS",
         "KOZAA.IS","MAVI.IS","METRO.IS","MGROS.IS","MPARK.IS",
         "NTHOL.IS","NETAS.IS","ODAS.IS","OTKAR.IS","PRKME.IS",
         "PARSN.IS","PGSUS.IS","PETKM.IS","POLHO.IS",
         "SASA.IS","SKBNK.IS","SISE.IS","SODA.IS","SOKM.IS",
         "TATGD.IS","TAVHL.IS","TKFEN.IS","THYAO.IS","TOASO.IS",
         "TRKCM.IS","TSKB.IS","TMSN.IS","TUPRS.IS",
         "TTKOM.IS","TTRAK.IS","TCELL.IS","HALKB.IS","ISCTR.IS",
         "ULKER.IS","VAKBN.IS","VERUS.IS","VESTL.IS","YKBNK.IS",
         "YATAS.IS","ZOREN.IS","FONET.IS","ALCTL.IS",
         "ARENA.IS","ARMDA.IS","DESPC.IS","DGATE.IS",
         "ESCOM.IS","KFEIN.IS"]


total_days=len(yf.download(indeces[0], start="2019-08-02", end=today))
stock_objects=[]

for ids in range(n_of_stocks):
    stock_objects.append(Stocks(ids,indeces[ids]))
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
[*********************100%***********************]  1 of 1 completed
In [3]:
import pandas as pd
import numpy as np
from datetime import datetime
import matplotlib.pyplot as plt
import yfinance as yf
import datetime
from datetime import date
today = datetime.datetime.now()

df = yf.download("AFYON.IS", start="2019-08-02", end=today)
rolling_mean = df.Close.rolling(window=20).mean()
rolling_mean2 = df.Close.rolling(window=50).mean()
exp1 = df.Close.ewm(span=20, adjust=True).mean()
exp2 =  df.Close.ewm(span=50, adjust=True).mean()
plt.plot(df.index, df.Close, label='AMD')
plt.plot(df.index, exp1, label='20 Day EMA',color='red')
plt.plot(df.index, exp2, label='50 Day EMA',color='green')
#plt.plot(df.index, rolling_mean, label='20 Day SMA', color='orange')
#plt.plot(df.index, rolling_mean2, label='50 Day SMA', color='magenta')
plt.legend(loc='upper left')
plt.show()
[*********************100%***********************]  1 of 1 completed
In [4]:
import matplotlib.pyplot as plt
fig, axs = plt.subplots(n_of_stocks,figsize=(15,500))
for i in range(n_of_stocks):
    axs[i].plot(stock_objects[i].data.index,stock_objects[i].stock_hist)
    axs[i].plot(stock_objects[i].data.index,stock_objects[i].exp,label='20 Day EMA',color='red')
    #axs[i].plot(stock_objects[i].data.index,stock_objects[i].exp2,label='50 Day EMA',color='green')
    #axs[i].plot(stock_objects[i].data.index,stock_objects[i].rolling_mean,label='20 Day SMA', color='orange')
    axs[i].plot(stock_objects[i].data.index,stock_objects[i].rolling_mean2,label='50 Day SMA', color='magenta')
    axs[i].set_title(indeces[stock_objects[i].id])
    axs[i].legend(loc='upper left')
In [ ]: